from django.db import models

from hotels.models import Hotel
from django.contrib.auth.models import User

# Create your models here.

class EnumField(models.Field):
    def __init__(self, *args, **kwargs):
        super(EnumField, self).__init__(*args, **kwargs)
        assert self.choices, "Need choices for enumeration"

    def db_type(self, connection):
        if not all(isinstance(col, basestring) for col, _ in self.choices):
            raise ValueError("MySQL ENUM values should be strings")
        return "ENUM({})".format(','.join("'{}'".format(col) 
                                          for col, _ in self.choices))

class RoomType(EnumField, models.CharField):
    def __init__(self, *args, **kwargs):
        room_type = [('single', 'single'),
                   ('double', 'double'),
                  ]
        super(RoomType, self).__init__(*args, choices=room_type, **kwargs)


class Room(models.Model):
	"""docstring for Room"""
	id = models.AutoField(primary_key=True)
	room_no = models.IntegerField()
	night_price = models.IntegerField()
	room_type = RoomType(max_length=6)
	hotel_id = models.ForeignKey(Hotel)



class RegRooms(models.Model):
	"""docstring for reg_rooms"""
	room_id = models.ForeignKey(Room)
	hotel_id = models.ForeignKey(Hotel)
	user_id = models.ForeignKey(User)
	chkin_date = models.DateField()
	chkout_date = models.DateField()
	
	unique_together = (('room_id','hotel_id', 'chkin_date', 'chkout_date'),)
